package com.nf.health.app.inquiry;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.http.Apis;
import com.nf.health.app.utils.ScreentUtils;


/**
 * Created by hepann on 2016/10/8.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author hepann
 * @Description 问诊界面点击问号时提示, 加载webview
 * @email he_pann@163.com
 */
public class InquiryHintDialog extends Dialog {

    private Context ctx;
    private Button btnIKnow;
    private WebView wv;
    private View mContent;
    private TextView tvTitle;
    private Display d;
    private WindowManager.LayoutParams p;
    private LinearLayout ll_content_inquire;
    public InquiryHintDialog(Context context) {
        //设置style
        super(context, R.style.dialog3);
        this.ctx = context;
        init();
    }

    //设置布局
    private void init() {
        setContentView(R.layout.dialog_inquiry_hint);
        btnIKnow = (Button) findViewById(R.id.btn_i_know);
        wv = (WebView) findViewById(R.id.wv_msg);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        mContent = findViewById(R.id.ll_content);
        ll_content_inquire = (LinearLayout) findViewById(R.id.ll_content_inquire);

        //设置大小
        /*LinearLayout.LayoutParams p = (LinearLayout.LayoutParams) mContent.getLayoutParams();
        p.width = (int) (ScreentUtils.getScreenWidth(ctx) * .8);
        p.height = (int) (ScreentUtils.getScreenHeight(ctx) * .5);
        mContent.setLayoutParams(p);*/
        setCircleDialogAtter(0.8,0.5);
        //监听
        btnIKnow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        //webView监听回调
        WebChromeClient wvcc = new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                //设置标题
                tvTitle.setText("" +title);
            }

        };
        // 设置setWebChromeClient对象
       wv.setWebChromeClient(wvcc);

        // 创建WebViewClient对象
        WebViewClient wvc = new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 使用自己的WebView组件来响应Url加载事件，而不是使用默认浏览器器加载页面
                wv.loadUrl(url + Apis.WEBVIEW_PLETEFORM);
                // 消耗掉这个事件。
                return true;
            }
        };
        wv.setWebViewClient(wvc);

    }

    @Override
    protected void onStart() {
        super.onStart();
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }


    public void setTitle(String title){
        tvTitle.setText(title);
    }
    public void setButtonSize(int buttonSize){
        btnIKnow.setTextSize(buttonSize);
    }

    public void setWebContent(String url){
        wv.loadUrl(url);
    }
    public InquiryHintDialog setMyOnClickListener(View.OnClickListener onClickListener){
        btnIKnow.setOnClickListener(onClickListener);
        return this;
    };
    public InquiryHintDialog setMyCancelable(boolean isCancle){
        setCancelable(isCancle);
        return this;
    };
    /***
     * 设置dialog的宽高，带有背景黑色的
     *****/
    public void setCircleDialogAtter(double widthValue, double heithValue) {
        ViewGroup.LayoutParams para = ll_content_inquire.getLayoutParams();
        WindowManager m = getWindow().getWindowManager();
        d = m.getDefaultDisplay();  //为获取屏幕宽、高
        p = getWindow().getAttributes();  //获取对话框当前的参数值
        para.height = (int) (d.getHeight() * heithValue);
        para.width = (int) (d.getWidth() * widthValue);
        ll_content_inquire.setLayoutParams(para);

    }
}
